<template>
  <div class="home">
    <el-container>
      <el-header>
        <div class="header-content">
          <h2>后台管理系统</h2>
          <el-button type="danger" @click="handleLogout">退出登录</el-button>
        </div>
      </el-header>
      <el-main>
        <h1>欢迎使用后台管理系统</h1>
        <p>当前用户：{{ currentUser?.username }}</p>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import { computed } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

export default {
  name: 'Home',
  setup() {
    const store = useStore()
    const router = useRouter()
    const currentUser = computed(() => store.getters.currentUser)

    const handleLogout = () => {
      store.dispatch('logout')
      ElMessage.success('已退出登录')
      router.push('/login')
    }

    return {
      currentUser,
      handleLogout
    }
  }
}
</script>

<style scoped>
.home {
  height: 100vh;
}

.el-header {
  background-color: #409EFF;
  color: white;
  line-height: 60px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-content h2 {
  margin: 0;
}

.el-main {
  padding: 20px;
  text-align: center;
}
</style> 